<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>搭建主从 | 欢迎学习Redis课程</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../redis/da-jian-ji-qun.html" />
    
    
    <link rel="prev" href="../redis/yu-python-jiao-hu/string.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="1.6"
        data-chapter-title="搭建主从"
        data-filepath="redis/da-jian-zhu-cong.md"
        data-basepath=".."
        data-revision="Sun Apr 15 2018 01:48:52 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        课程介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="redis.html">
            
                
                    <a href="../redis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        Redis
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="redis/an-zhuang.html">
            
                
                    <a href="../redis/an-zhuang.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="redis/pei-zhi.html">
            
                
                    <a href="../redis/pei-zhi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="redis/fu-wu-duan-he-ke-hu-duan-ming-ling.html">
            
                
                    <a href="../redis/fu-wu-duan-he-ke-hu-duan-ming-ling.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        服务端和客户端命令
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="redis/shu-ju-cao-zuo.html">
            
                
                    <a href="../redis/shu-ju-cao-zuo.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        数据操作
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="redis/shu-ju-cao-zuo/string.html">
            
                
                    <a href="../redis/shu-ju-cao-zuo/string.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.1.</b>
                        
                        string
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="redis/shu-ju-cao-zuo/jian-ming-ling.html">
            
                
                    <a href="../redis/shu-ju-cao-zuo/jian-ming-ling.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.2.</b>
                        
                        键命令
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="redis/shu-ju-cao-zuo/hash.html">
            
                
                    <a href="../redis/shu-ju-cao-zuo/hash.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.3.</b>
                        
                        hash
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="redis/shu-ju-cao-zuo/list.html">
            
                
                    <a href="../redis/shu-ju-cao-zuo/list.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.4.</b>
                        
                        list
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="redis/shu-ju-cao-zuo/set.html">
            
                
                    <a href="../redis/shu-ju-cao-zuo/set.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.5.</b>
                        
                        set
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="redis/shu-ju-cao-zuo/zset.html">
            
                
                    <a href="../redis/shu-ju-cao-zuo/zset.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.6.</b>
                        
                        zset
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="redis/yu-python-jiao-hu.html">
            
                
                    <a href="../redis/yu-python-jiao-hu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        与Python交互
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="redis/yu-python-jiao-hu/strictredis.html">
            
                
                    <a href="../redis/yu-python-jiao-hu/strictredis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.1.</b>
                        
                        StrictRedis
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="redis/yu-python-jiao-hu/string.html">
            
                
                    <a href="../redis/yu-python-jiao-hu/string.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.2.</b>
                        
                        string
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="1.6" data-path="redis/da-jian-zhu-cong.html">
            
                
                    <a href="../redis/da-jian-zhu-cong.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        搭建主从
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="redis/da-jian-ji-qun.html">
            
                
                    <a href="../redis/da-jian-ji-qun.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        搭建集群
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="redis/da-jian-ji-qun/pei-zhi-ji-qi-1.html">
            
                
                    <a href="../redis/da-jian-ji-qun/pei-zhi-ji-qi-1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.1.</b>
                        
                        配置机器1
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="redis/da-jian-ji-qun/pei-zhi-ji-qi-2.html">
            
                
                    <a href="../redis/da-jian-ji-qun/pei-zhi-ji-qi-2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.2.</b>
                        
                        配置机器2
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="redis/da-jian-ji-qun/chuang-jian-ji-qun.html">
            
                
                    <a href="../redis/da-jian-ji-qun/chuang-jian-ji-qun.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.3.</b>
                        
                        创建集群
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="redis/da-jian-ji-qun/yu-python-jiao-hu.html">
            
                
                    <a href="../redis/da-jian-ji-qun/yu-python-jiao-hu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.4.</b>
                        
                        与Python交互
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >欢迎学习Redis课程</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x5B66;&#x4E60;&#x76EE;&#x6807;">&#x5B66;&#x4E60;&#x76EE;&#x6807; </h1>
<ul>
<li>&#x80FD;&#x591F;&#x6839;&#x636E;&#x8BFE;&#x4EF6;&#x4E2D;&#x7684;&#x6B65;&#x9AA4;&#x642D;&#x5EFA; Redis &#x7684;&#x4E3B;&#x4ECE;</li>
</ul>
<h1 id="&#x4E3B;&#x4ECE;&#x6982;&#x5FF5;">&#x4E3B;&#x4ECE;&#x6982;&#x5FF5; </h1>
<ul>
<li>&#x2F00;&#x4E2A;master&#x53EF;&#x4EE5;&#x62E5;&#x6709;&#x591A;&#x4E2A;slave&#xFF0C;&#x2F00;&#x4E2A;slave&#x2F1C;&#x53EF;&#x4EE5;&#x62E5;&#x6709;&#x591A;&#x4E2A;slave&#xFF0C;&#x5982;&#x6B64;&#x4E0B;&#x53BB;&#xFF0C;&#x5F62;&#x6210;&#x4E86;&#x5F3A;&#x2F24;&#x7684;&#x591A;&#x7EA7;&#x670D;&#x52A1;&#x5668;&#x96C6;&#x7FA4;&#x67B6;&#x6784;</li>
<li>master&#x7528;&#x6765;&#x5199;&#x6570;&#x636E;&#xFF0C;slave&#x7528;&#x6765;&#x8BFB;&#x6570;&#x636E;&#xFF0C;&#x7ECF;&#x7EDF;&#x8BA1;&#xFF1A;&#x7F51;&#x7AD9;&#x7684;&#x8BFB;&#x5199;&#x6BD4;&#x7387;&#x662F;10:1</li>
<li><p>&#x901A;&#x8FC7;&#x4E3B;&#x4ECE;&#x914D;&#x7F6E;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x8BFB;&#x5199;&#x5206;&#x79BB;</p>
<p><img src="../assets/p1_5.png" alt=""></p>
</li>
<li><p>master&#x548C;slave&#x90FD;&#x662F;&#x4E00;&#x4E2A;redis&#x5B9E;&#x4F8B;(redis&#x670D;&#x52A1;)</p>
</li>
</ul>
<h1 id="&#x4E3B;&#x4ECE;&#x914D;&#x7F6E;">&#x4E3B;&#x4ECE;&#x914D;&#x7F6E; </h1>
<h2 id="&#x914D;&#x7F6E;&#x4E3B;">&#x914D;&#x7F6E;&#x4E3B; </h2>
<ul>
<li><p>&#x67E5;&#x770B;&#x5F53;&#x524D;&#x4E3B;&#x673A;&#x7684;ip&#x5730;&#x5740;</p>
<blockquote>
<p>ifconfig</p>
</blockquote>
<p><img src="../assets/p1_10.png" alt="" title="ifconfig"></p>
</li>
<li><p>&#x4FEE;&#x6539;etc/redis/redis.conf&#x6587;&#x4EF6;</p>
<blockquote>
<p>sudo vi redis.conf<br>bind 192.168.26.128</p>
</blockquote>
</li>
<li><p>&#x91CD;&#x542F;redis&#x670D;&#x52A1;</p>
<blockquote>
<p>sudo service redis stop<br>redis-server redis.conf</p>
</blockquote>
</li>
</ul>
<h2 id="&#x914D;&#x7F6E;&#x4ECE;">&#x914D;&#x7F6E;&#x4ECE; </h2>
<ul>
<li><p>&#x590D;&#x5236;etc/redis/redis.conf&#x6587;&#x4EF6;</p>
<blockquote>
<p>sudo cp redis.conf ./slave.conf</p>
</blockquote>
</li>
<li><p>&#x4FEE;&#x6539;redis/slave.conf&#x6587;&#x4EF6;</p>
<blockquote>
<p>sudo vi slave.conf</p>
</blockquote>
</li>
<li><p>&#x7F16;&#x8F91;&#x5185;&#x5BB9;</p>
<blockquote>
<p>bind 192.168.26.128<br>slaveof 192.168.26.128 6379<br>port 6378</p>
</blockquote>
</li>
<li><p>redis&#x670D;&#x52A1;</p>
<blockquote>
<p>sudo redis-server slave.conf</p>
</blockquote>
</li>
<li><p>&#x67E5;&#x770B;&#x4E3B;&#x4ECE;&#x5173;&#x7CFB;</p>
<blockquote>
<p>redis-cli -h 192.168.26.128 info Replication</p>
</blockquote>
<p><img src="../assets/p1_9.png" alt="" title="&#x4E3B;&#x4ECE;&#x5173;&#x7CFB;"></p>
</li>
</ul>
<h2 id="&#x6570;&#x636E;&#x64CD;&#x4F5C;">&#x6570;&#x636E;&#x64CD;&#x4F5C; </h2>
<ul>
<li><p>&#x5728;master&#x548C;slave&#x5206;&#x522B;&#x6267;&#x2F8F;info&#x547D;&#x4EE4;&#xFF0C;&#x67E5;&#x770B;&#x8F93;&#x51FA;&#x4FE1;&#x606F; &#x8FDB;&#x5165;&#x4E3B;&#x5BA2;&#x6237;&#x7AEF;</p>
<blockquote>
<p>redis-cli -h 192.168.26.128 -p 6379</p>
</blockquote>
</li>
<li><p>&#x8FDB;&#x5165;&#x4ECE;&#x7684;&#x5BA2;&#x6237;&#x7AEF;</p>
<blockquote>
<p>redis-cli -h 192.168.26.128 -p 6378</p>
</blockquote>
</li>
<li><p>&#x5728;master&#x4E0A;&#x5199;&#x6570;&#x636E;</p>
<blockquote>
<p>set aa aa</p>
</blockquote>
<p><img src="../assets/p1_56.png" alt="" title="master&#x5199;&#x6570;&#x636E;"></p>
</li>
<li><p>&#x5728;slave&#x4E0A;&#x8BFB;&#x6570;&#x636E;</p>
<blockquote>
<p>get aa</p>
</blockquote>
</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../redis/yu-python-jiao-hu/string.html" class="navigation navigation-prev " aria-label="Previous page: string"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../redis/da-jian-ji-qun.html" class="navigation navigation-next " aria-label="Next page: 搭建集群"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
